/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author root
 */
@Entity
public class AddInfoPersonage extends AbstractEntity{

    @ManyToOne
    @JoinColumn(name="personage_id")
    private Personage personage;
    
    @ManyToOne
    @JoinColumn(name="additional_info_type_id")
    private AdditionalInfoType additionalInfoType;
    
    public AddInfoPersonage() {
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String hash = ""
                    + ((this.getAdditionalInfoType() != null) ? this.getAdditionalInfoType().getId() : null)
                    + ((this.getPersonage() != null) ? this.getPersonage().getId() : null);
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public AddInfoPersonage(Personage personage, AdditionalInfoType additionalInfoType) {
        this.personage = personage;
        this.additionalInfoType = additionalInfoType;
    }

    public AdditionalInfoType getAdditionalInfoType() {
        return additionalInfoType;
    }

    public void setAdditionalInfoType(AdditionalInfoType additionalInfoType) {
        this.additionalInfoType = additionalInfoType;
    }

    public Personage getPersonage() {
        return personage;
    }

    public void setPersonage(Personage personage) {
        this.personage = personage;
    }
}
